
#include "Scene/Game/Map.hpp"

using namespace Scene::Game;

Map::Map() : _width(0), _height(0), _blocks(0)
{

}

Map::Map(int width, int height) : _width(width), _height(height), _blocks(0)
{
    this->_blocks = new MapBlock*[this->_width];
    for (int i = 0; i < this->_width; i++)
        this->_blocks[i] = new MapBlock[this->_height];
}

Map::~Map()
{
    for (int i = 0; i < this->_width; i++)
        delete [] this->_blocks[i];
    delete [] this->_blocks;
}

int     Map::getWidth() const
{
    return this->_width;
}

void    Map::setWidth(int width)
{
    this->_width = width;
}

int     Map::getHeight() const
{
    return this->_height;
}

void    Map::setHeight(int height)
{
    this->_height = height;
}

MapItem*    Map::getItem(std::string const & name)
{
    ItemMap::iterator   it = this->_items.find(name);
    if (it != this->_items.end())
        return it->second;
    return 0;
}

void    Map::addItem(std::string const & name, MapItem* item)
{
    this->_items["name"] = item;
}

MapBlock*   Map::getBlock(int x, int y) const
{
    if (x < this->_width && y < this->_height)
        return &this->_blocks[x][y];
    return 0;
}

void         Map::setBlock(int x, int y, MapBlock const & block)
{
    if (x < this->_width && y < this->_height)
        this->_blocks[x][y] = block;
}
